<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>门户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <!--引入本地的css样式-->
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/admin.css" media="all">

</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">关键词和客户名搜索</label>

                    <div class="layui-input-block">
                        <input type="text" id="kw_name" name="kw_name" placeholder="输入关键词" autocomplete="off" class="layui-input">

                        <input type="text" id="customer_name" name="customer_name" placeholder="输入客户" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-admin" id="btn_search" lay-submit lay-filter="LAY-user-back-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
<!--                    <button class="layui-btn layuiadmin-btn-admin" lay-event="batchdel" >删除</button>-->
                    <button class="layui-btn layuiadmin-btn-admin" lay-event="add" id="add_employee" data-type="add_employee">添加</button>
                </div>
            </script>

            <!--<script type="text/html" id="toolbarDemo">-->
            <!--<div style="padding-bottom: 10px;">-->
            <!--<button class="layui-btn layuiadmin-btn-admin" lay-event="batchdel">删除</button>-->
            <!--<button class="layui-btn layuiadmin-btn-admin" id="add_employee" data-type="add_employee">添加</button>-->
            <!--</div>-->
            <!--</script>-->
            <!--数据表格-->
            <table class="layui-hide" id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>

            <script type="text/html" id="employeeSexTpl">
                {{#  if(d.employee_sex == 1){ }}
                <span>男</span>
                {{#  } else if(d.employee_sex == 2){ }}
                <span>女</span>
                {{#  } }}
            </script>
            <script type="text/html" id="statusTpl">
                {{#  if(d.status == 1){ }}
                <span>正常</span>
                {{#  } else if(d.status == 2){ }}
                <button type="button" class="layui-btn-xs layui-btn-disabled">冻结</button>
                {{#  } else if(d.status == 3){ }}
                <button type="button" class="layui-btn-xs layui-btn-danger">删除</button>
                {{#  } }}
            </script>


            <script type="text/html" id="buttonTpl">
                {{#  if(d.check == true){ }}
                <button class="layui-btn layui-btn-xs">已审核</button>
                {{#  } else { }}
                <button class="layui-btn layui-btn-primary layui-btn-xs">未审核</button>
                {{#  } }}
            </script>

            <script type="text/html" id="table-useradmin-admin">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                {{#  if(d.role == '超级管理员'){ }}
<!--                <a class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                {{#  } else { }}
<!--                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                {{#  } }}
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<!--                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
            </script>


        </div>
    </div>
</div>

<script src="../../static/js/jquery-3.6.0.min.js"></script>
<!--引入本地layui.js-->
<script src="../../static/layui/layui.js"></script>
<!--js-->
<script type="text/javascript">
    layui.config({
        base: '../../static/layui/layuiadmin/' //静态资源所在路径js
    }).extend({
        index: 'lib/index' //主入口模块
    }).use('index');
</script>

<script type="text/javascript">
    layui.use(['table','form'], function(){
        var table = layui.table;
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

        table.render({
            elem: '#LAY-user-back-manage'//绑定到哪一个表格：#id值
            ,url:'/Cloud/selectGate'//servlet绑定路径
            ,title: '门户数据表'//标题
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,page: true
            ,limit:5//修改页码的默认传参
            ,limits:[5,10,15,20]
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'kw_id', title:'序号', fixed: 'left', unresize: true, sort: true}
                ,{field:'kw_name', title:'门户名称',}
                ,{field:'customer_name', title:'客户名称'}
                ,{field:'represent', title:'法人代表'}
                ,{field:'agent_name', title:'代理商'}
                ,{field:'registration_time', title:'注册时间',sort: true}
                ,{field:'company_type', title:'类型'}
                ,{field:'use_state', title:'状态'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]

        });

        //搜索点击事件
        $("#btn_search").click(function () {
            var kw_name = $("#kw_name").val();
            var customer_name = $("#customer_name").val();
            //执行重载
            table.reload('LAY-user-back-manage', {
                url:'/Cloud/selectGate',
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    kw_name: kw_name,
                    customer_name:customer_name
                }
            });
        });

        //监听行工具事件
        table.on('tool(LAY-user-back-manage)', function(obj){
            var data = obj.data;//选中的当前行的数
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    //通过ajax实现真正的删除
                    $.ajax({
                        url:"/employee/del",
                        type:"post",
                        data:{id:data.employee_id},
                        dataType:"json",
                        success:function (res) {
                            layer.alert(res.msg);
                            obj.del();//页面删除obj.del()
                            layer.close(index);
                        }
                    })

                });
            } else if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: '编辑移动云端信息'
                    ,content: 'edit.html'
                    ,area: ['750px', '850px']
                    ,maxmin:true
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var submitData = body.find('#myform').serialize();
                        //提交 Ajax 成功后，静态表单中的数据
                        $.ajax({
                            url:"/Cloud/changeCloud",
                            type:"post",
                            data:submitData,
                            dataType:"json",
                            success:function (res) {
                                if(res.code == 200){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                if(res.code == 500){
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 1000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                                layer.close(index); //关闭弹层

                            }
                        })

                    }
                    ,success: function (layero, index) {//点击弹出框时，执行的函数。
                        //获取弹出编辑框的body内容
                        var body = layer.getChildFrame('body', index);
                        //移动云端信息
                        body.find("input[name=cl_accout]").val(data.cl_accout);
                        //找到body中input输入框，向employee_name输入框中塞入选中行的值
                        body.find("input[name=cl_password]").val(data.cl_password);
                        body.find("input[name=kw_name]").val(data.kw_name);
                        body.find("input[name=cloud_id]").val(data.cloud_id);
                        body.find("input[name=cl_address]").val(data.cl_address);
                        body.find("input[name=cl_dacstand]").val(data.cl_dacstand);
                        body.find("input[name=cl_qcdaand]").val(data.cl_qcdaand);
                        body.find("input[name=cl_dacstios]").val(data.cl_dacstios);
                        body.find("input[name=cl_qcdaios]").val(data.cl_qcdaios);
                        body.find("input[name=application_begin]").val(data.application_begin);
                        body.find("input[name=application_end]").val(data.application_end);
                        //基础信息
                        body.find("input[name=company_name]").val(data.company_name);
                        body.find("input[name=state]").val(data.state);
                        body.find("input[name=company_type]").val(data.company_type);
                        body.find("input[name=company_home]").val(data.company_home);
                        //门户信息
                        body.find("input[name=represent]").val(data.represent);
                        body.find("input[name=registration_time]").val(data.registration_time);
                        body.find("input[name=document_type]").val(data.document_type);
                        body.find("input[name=document_num]").val(data.document_num);
                        body.find("input[name=country]").val(data.country);
                        body.find("input[name=provinces]").val(data.provinces);
                        body.find("input[name=area]").val(data.area);
                        body.find("input[name=city]").val(data.city);
                        body.find("input[name=company_tel]").val(data.company_tel);
                        body.find("input[name=company_fax]").val(data.company_fax);
                        body.find("input[name=company_address]").val(data.company_address);
                        body.find("input[name=note]").val(data.note);


                    }
                });
            }
        });

        //头工具栏事件
        table.on('toolbar(LAY-user-back-manage)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'batchdel':
                    var data = checkStatus.data;
                    if(data.length < 1){
                        layer.msg('未选中删除的数据');
                    }else{
                        //删除，通过ajax方式进行删除
                        layer.confirm('真的删除选中行的数据么', function(index){
                            var ids = new Array();
                            $.each(data,function (index,item) {
                                //循环遍历勾选数据，只将要删除数据的id号获取处理，塞给数组对象
                                ids.push(item.employee_id);
                                console.log(ids);
                            })

                            //通过ajax传递给后端
                            $.ajax({
                                url:"/employee/batchdel",
                                type:"post",
                                data:{ids:ids},
                                traditional:true,//单纯的传递数组，需要将其进行传统序列化操作
                                dataType:"json",
                                success:function (res) {
                                    layer.msg(res.msg, {
                                        offset: '15px'
                                        ,icon: 1
                                        ,time: 2000
                                    },function () {
                                        //刷新
                                        window.location.reload();
                                    });
                                }
                            })
                        });

                    }
                    break;
                case 'add':
                    layer.open({
                        type: 2
                        ,title: '添加门户'
                        ,content: 'add.html'
                        ,area: ['450px', '550px']
                        ,maxmin:true
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            var submitData = body.find('#myform').serialize();//把add.html中表单中所有参数通过Ajax的data:submitData传递给服务器端
                            //提交 Ajax 成功后，静态表单中的数据
                            $.ajax({
                                url:"/Cloud/addCloud",
                                type:"post",
                                data:submitData,//所有表单中参数值
                                dataType:"json",
                                success:function (res) {
                                    if(res.code == 200){
                                        layer.msg(res.msg, {
                                            offset: '15px'
                                            ,icon: 1
                                            ,time: 1000
                                        },function () {
                                            //刷新
                                            window.location.reload();
                                        });
                                    }
                                    if(res.code == 500){
                                        layer.msg(res.msg, {
                                            offset: '15px'
                                            ,icon: 1
                                            ,time: 1000
                                        },function () {
                                            //刷新
                                            window.location.reload();
                                        });
                                    }
                                    layer.close(index); //关闭弹层

                                }
                            })


//                      var iframeWindow = window['layui-layer-iframe'+ index]
//                          ,submitID = 'LAY-user-back-submit'
//                          ,submit = layero.find('iframe').contents().find('#'+ submitID);
//                      //监听提交
//                      iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
//                          var field = data.field; //获取提交的字段
//                          alert("ok");
//                          console.log(field);
//
//
//                          table.reload('LAY-user-front-submit'); //数据刷新
//                          layer.close(index); //关闭弹层
//                      });

//                      submit.trigger('click');
                        }
                    });
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });


    });
</script>

</body>
</html>

